class RangeIterator {
  constructor(start, stop) {
    this.value = start;
    this.stop = stop;
  }

  [Symbol.iterator]() { return this; }

  next() {
    var value = this.value;
    if (value < this.stop) {
      this.value++;
      return {done: false, value: value};
    }
    return {done: true, value: undefined};
  }
}

function range(start, stop) {
  return new RangeIterator(start, stop);
}
const rangeIterator = range(0,3)

const it = rangeIterator[Symbol.iterator]()

console.log(it.next())


for (var value of rangeIterator) {
  console.log(value); // 0, 1, 2
}


